package cn.cocho.android.mc.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;

import cn.cocho.android.mc.R;
import cn.cocho.android.mc.base.BaseApplication;
import cn.cocho.android.mc.comp.button.McButton;
import cn.cocho.android.mc.log.LoggerUtils;
import cn.cocho.android.mc.storage.ApplicationCache;

/**
 * 所有Activity应该继承的类
 * 
 * @author HAIKANG SONG
 * @time 2013-4-25下午7:18:51
 */
public class BaseActivity extends Activity implements ActivityInterface {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ApplicationCache.context = this;
		BaseApplication.getInstance().addActivity(this);
		try {
			before();
			hideTitle();
			init();
			initAfter();
			over();
		} catch (Exception e) {
			ActivityUtils.showLongMessage(R.string.has_error);
			LoggerUtils.error(e);
		}
	}


	@Override
	public void finish() {
		super.finish();
	}

	public void hideTitle() {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
	}

	public void hideStateBar() {
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
	}

	public void startActivity(Class<?> cls) {
//		Intent intent = ActivityCompanyManager.getIntent(this, cls);
        Intent intent = new Intent(this, cls);
		startActivity(intent);
	}

	public void initFinishBtn(int finishBtnId) {
		View finishBtn = (View) findViewById(finishBtnId);
		finishBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
	}

	public void initOpenActivityBtn(int homeBtnId, final Class<?> cls) {
		McButton finishBtn = (McButton) findViewById(homeBtnId);
		finishBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				startActivity(cls);
			}
		});
	}

	@Override
	public void before() {

	}

	@Override
	public void init() {

	}

	@Override
	public void initAfter() {

	}
	
	@Override
	public void over() {

	}

}
